package fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.statusdetection;

import java.util.Iterator;
import java.util.Arrays;

import fr.inria.diagen.core.exception.InvocationException;
import fr.inria.diagen.core.service.local.Service;

import fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DeviceStatus;


import fr.inria.diagen.core.server.local.EventSubscription;
public class EnvironmentSensorDeviceComposite implements Iterable<EnvironmentSensorDeviceProxy> {
    private EnvironmentSensorDeviceProxy[] proxys;
    private Service abstractComponent;
    
    public EnvironmentSensorDeviceComposite(EnvironmentSensorDeviceProxy[] proxys, Service abstractComponent) {
      this.proxys=proxys;
      this.abstractComponent=abstractComponent;
    }
    
    public Iterator<EnvironmentSensorDeviceProxy> iterator() {
        return Arrays.asList(proxys).iterator();
    }


    public void subscribeStatus() {
      for(EnvironmentSensorDeviceProxy proxy : proxys) {
        abstractComponent.getServer().subscribe(new EventSubscription(proxy.getRemoteServiceInfo(), abstractComponent.getServiceInfo(), "status"), 3600);
      } 
    }

    public boolean isEmpty() {
     return proxys.length == 0;
    }

    public int size() {
      return proxys.length;
    }
    
    public EnvironmentSensorDeviceProxy anyOne() {
      try {
        return proxys[0];
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
  }
}